package com.approval.approvalapp.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by louyulin on 2019/3/18.
 * SharePerferce 缓存工具类 存放键值对
 */

public class SpUtil {
    public static final String SP_NAME = "config";
    private static SharedPreferences sp;
    // 存储用户名
    public static final String USER_RUN_NICKNAME = "userNickname";
    // 存储用户id
    public static final String USER_RUN_ID = "userRunId";
    //用户头像
    public static final String USER_AVATER = "userAvater";
    //单位
    public static final String UNIT_NAME = "unit_name";
    //职务
    public static final String POSITION = "position";
    //区域编码
    public static final String REGION_CODE = "region_code";
    //组织编码
    public static final String ORG_CODE = "org_code";
    //账号
    public static final String USER_NAME = "user_name";
    public static final String F_userid = "f_userid";
    public static final String F_orgcode = "f_orgcode";
    public static final String F_orgname = "f_orgname";
    public static final String Usertype = "usertype";
    public static final String SJLD = "SJLD";
    public static final String SJLDN = "SJLDN";
    public static final String GZFW1 = "GZFW1";
    public static final String GH = "GH";
    public static final String INDEXCACHE = "INDEXCACHE";
    public static final String CENCACHE = "CENCACHE";
    public static final String orgename = "orgename";







    public static void saveString(Context context, String key, String value) {
        if (sp == null)
            sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        sp.edit().putString(key, value).commit();
    }

    public static String getString(Context context, String key, String defValue) {
        if (sp == null)
            sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);

        return sp.getString(key, defValue);
    }

    public static void saveBoolean(Context context, String key, boolean value) {
        if (sp == null)
            sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        sp.edit().putBoolean(key, value).commit();
    }

    public static boolean getBoolean(Context context, String key, boolean defValue) {
        if (sp == null)
            sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return sp.getBoolean(key, defValue);

    }

    public static void saveInt(Context context, String key, int value) {
        if (sp == null)
            sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        sp.edit().putInt(key, value).commit();
    }

    public static int getInt(Context context, String key, int defValue) {
        if (sp == null)
            sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return sp.getInt(key, defValue);
    }

    public static void clearAllSp(Context context){
        if (sp == null){
            sp = context.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
           sp.edit().clear().commit();
        }
    }


}
